import { fileURLToPath, URL } from 'node:url'
import { resolve } from 'node:path'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import dts from "vite-plugin-dts"

import tailwindcss from '@tailwindcss/vite'

// https://vite.dev/config/
export default defineConfig({
    plugins: [
        vue(),
        vueDevTools(),
        tailwindcss(),
        dts({ 
            insertTypesEntry: true,
            rollupTypes: true,
            outDir: "dist",
            tsconfigPath: resolve(__dirname, "tsconfig.app.json")
        })
    ], build: {
        lib: {
            entry: resolve(__dirname, "src/components/index.ts"),
            name: "LibVue", // UMD 模式下的全局变量名
            fileName: (format) => `lib-vue.${format}.js`,
            formats: ["es", "umd"],
            cssFileName: "index" // 自定义 CSS 文件名
        },
        rollupOptions: {
            external: ["vue"], // 不要把 vue 打包进去
            output: {
                globals: {
                    vue: "Vue"
                }
            }
        }
    },
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url))
        },
    },
})